package com;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ResponseIOServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       /*
       resp.getWriter();//字符流，常用于回传字符串 二取一i
        resp.getOutputStream();//字节流 常用于下载
        */
        /**
         * System.out.println(resp.getCharacterEncoding()); 默认字符集型号
         *         resp.setCharacterEncoding("UTF-8");
         //通过响应头，色湖之游览器也使用utf-8字符集
        resp.setHeader("Content-Type","text/html;charset=UTF-8");
         */
        //设置服务器字符集为utf-8

        //同时设置服务器和客户端都使用utf-8字符集，还设置了响应
        //获取源对象前调用
        resp.setContentType("text/html;charset=UTF-8");
        //要求：往客户端回传 字符串数据
        PrintWriter writer=resp.getWriter();
        writer.write("你猜");
    }
}
